#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'z417'
import os
import sys
from .log import L

BASEDIR = os.getcwd()
sys_conf_path = os.path.dirname(os.path.dirname(__file__))
OSTYPE = sys.platform


class Dict(dict):
    '''
    Simple dict but support access as x.y style.
    '''

    def __init__(self, names=(), values=(), **kw):
        super(Dict, self).__init__(**kw)
        for k, v in zip(names, values):
            self[k] = v

    def __getattr__(self, key):
        try:
            return self[key]
        except KeyError:
            raise AttributeError(r"'Dict' object has no attribute '%s'" % key)

    def __setattr__(self, key, value):
        self[key] = value


def to_Dict(d):
    D = Dict()
    for k, v in d.items():
        D[k] = to_Dict(v) if isinstance(v, dict) else v
    return D


__all__ = [
    'L',
    'BASEDIR',
    'Dict',
    'to_Dict',
    'sys_conf_path',
    'OSTYPE'
]
